unit map;

interface

uses
  sysutils,
  Picfile,
  Engine,
  NPC;

type
  TMapOBJtype = (OBJ_None, OBJ_NPC, OBJ_Box, OBJ_Dead, OBJ_Obj, OBJ_Event);
  //鍦板浘鐗╀綋锛圢PC锛屽疂绠憋紝灏镐綋绛夛級
  TObject = record
    OBJtype: TMapOBJtype;
    OBJindex: integer;
  end;

  TObjectList = record
    OBJnum: integer;
    Objects: array of TObject;
  end;

  TMapObject = record
    OBJtype: TMapOBJtype;
    OBJindex: integer;
    x,y: integer;
  end;

  TMapObjectList = record
    OBJnum: integer;
    MapObject: array of TMapObject;
  end;

  //鍦板浘鍧楁牸寮?
  TMapTile = record
    Pic: integer; //鍥剧墖鏂囦欢绱㈠紩
    num: integer; //鍥剧墖绱㈠紩
    ObjectList: TObjectList;
  end;
  //鍦板浘灞傛牸寮?
  TmapLayer = record
    width: integer;
    height: integer;
    tile: array of array of TMapTile;
  end;
  //鍦板浘鏁版嵁鏍煎紡
  TmapData = record
    layernum: integer;
    layer: array of TMapLayer;
    OBJnum: integer;
    MapObjectList: TMapObjectList;
  end;

  Tmap = class
    Pic: TPicFile;
    Mapnum: integer;
    MapData: array of TMapData;
    MapNPC: TNPC;
    constructor Create; overload;
    procedure Release;
    Destructor Destroy; override;
    function DrawMapToBuf(): integer;
    function ReadMapFromFile(): integer;
    function ReadMapFromPak(): integer;
  end;

implementation

Destructor TMap.Destroy;
begin
  Release;
  inherited Destroy;
end;

constructor Tmap.Create;
begin
  inherited;
  pic := TpicFile.Create;
  MapNPC := TNPC.Create;
end;

procedure Tmap.Release;
var
  I, I2, I3, I4: integer;
begin
  for I := 0 to Mapnum - 1 do
  begin
    for I2 := 0 to Mapdata[I].layernum - 1 do
    begin
      for I3 := 0 to Mapdata[I].layer[I2].width do
        for I4 := 0 to Mapdata[I].layer[I2].Height do
          setlength(MapData[I].layer[I2].tile[I3][I4].OBJectlist.Objects, 0);
      setlength(MapData[I].layer[I2].tile, 0, 0);
    end;
    setlength(MapData[I].layer, 0);
    setlength(MapData[I].MapObjectList.MapObject, 0);
  end;

  pic.Release;
  MapNPC.Release;
end;

function Tmap.DrawMapToBuf(): integer;
begin
  //
end;

function Tmap.ReadMapFromFile(): integer;
begin
  //
end;

function Tmap.ReadMapFromPak(): integer;
begin
  //
end;

end.
